package advanced.practice._1005;

import java.io.PrintStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {


    public static void main(String[] args) {

        Scanner sc=new Scanner(System.in);
        PrintStream out=System.out;

        int M=sc.nextInt();
        int N=sc.nextInt();

        Map<Integer,Integer>map=new HashMap<>();

        int maxTime=0;
        int maxValue=-1;

        int ijMax=M*N;
        for(int i=0;i<ijMax;i++){
            int color=sc.nextInt();
            int times=1;
            if(map.containsKey(color)){
                times+=map.get(color);
                if(times>maxTime){
                    maxTime=times;
                    maxValue=color;
                }
            }
            map.put(color,times);
        }

        out.println(maxValue);
    }

}
